﻿using System;
using Lightray.Hattrick.ChppLib;
using Lightray.Hattrick.ChppLib.EntityTypes;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using DevDefined.OAuth.Framework;

namespace ChppPlay
{
    class Play2
    {
        public Play2()
        {
            WebFetcher fetcher = new WebFetcher(readTokenFromFile(), readSecretFromFile());
            //Economy economy = fetcher.MyEconomy();
            //Console.WriteLine("");
            //List<Match> matches = fetcher.MyRecentMatches();
            //for (int i = 0; i < matches.Count; i++)
            //{
            //    if (matches[i].Status == MatchStatus.FINISHED)
            //        matches[i] = fetcher.MatchDetails(matches[i].MatchID);
            //}
            //Match single = fetcher.MatchDetails(332468267);
            //332468267
            //318886677
            //StreamReader sr = new StreamReader(@"C:\Users\Nofar&Ran\Desktop\iTrick\ex4.txt");
            //String data = sr.ReadToEnd();
            //sr.Close();
            //List<CandidatePlayer> candidates = CandidatesParser.ParseCandidates(data);
            
            //Schedualer s = new Schedualer(new DateTime(2010, 10, 10, 10, 10, 10), new DateTime(2010, 10, 10, 10, 10, 10));
            

            #region Lineup Calculations
            //Console.WriteLine(DateTime.Now.ToString("mm:ss.fff"));
            EntityCollection<Player> players = fetcher.MyPlayers();
            //Console.WriteLine();
            ////Console.WriteLine(DateTime.Now.ToString("mm:ss.fff"));
            ////Console.WriteLine();

            int howManyWingbacks = 2;
            int howManyDefenders= 3;
            int howManyWingers= 0;
            int howManyMidfielders= 3;
            int howManyForwards= 2;
            ////Console.WriteLine(DateTime.Now.ToString("mm:ss.fff"));
            List<Player> newPlayers = new List<Player>();
            for (int i = 0; i < 10; i++)
            {
                newPlayers.Add(players[i]);
            }
            List<PlayerScores> lineup = Calculations.GetLineup(players.ToList(), Weather.Unknown, false, false,
                howManyWingbacks, howManyDefenders, howManyWingers, howManyMidfielders, howManyForwards);
            Formation best = Calculations.GetBestFormation(players.ToList(), Weather.Unknown, false);
            PlayerScores.Position weakest = Calculations.GetWeakestPositionInLineup(lineup);
            //Console.WriteLine(DateTime.Now.ToString("mm:ss.fff"));
            //List<NewAbilityScores> subs = Calculations.GetLineup(players, Weather.Unknown, false, 0, 1, 1, 1, 1);
            //Console.WriteLine(DateTime.Now.ToString("mm:ss.fff"));
            //List<NewAbilityScores> penaltys = Calculations.GetPenaltyShootoutOrder(lineup);
            //Player captain = Calculations.GetCaptain(lineup);
            //Player sp = Calculations.GetSetpiecesTaker(lineup);
            //Console.WriteLine();            
            //Console.WriteLine();
            #endregion
        }

        private IToken readTokenFromFile()
        {
            BinaryFormatter bf = new BinaryFormatter();
            return bf.Deserialize(File.OpenRead("mytoken.bin")) as IToken;
        }

        private string readSecretFromFile()
        {
            return File.ReadAllText("secret.txt");
        }
    }
}




